package com.zim.analysis.saika;

import com.zim.analysis.util.FormatUtils;

/**
 * 基础处理类
 * @author zi-m.cn
 *
 */
public abstract class BaseHandle {
    /**
     * 数据byte格式
     */
    protected byte[] message;
    
    /**
     * 数据string格式
     */
    protected String stringMsg;
    
    protected BaseHandle(byte[] bytes) throws Exception{
        this.message = bytes;
        init(bytes);
    }
    protected void init(byte[] bytes) throws Exception{
        byteToHexStr(bytes);
    }
    
    /**
     * byte to hex sting
     * @throws Exception
     */
    protected void byteToHexStr(byte[] bytes) throws Exception{
        this.stringMsg = FormatUtils.byteToHexStr(bytes); 
    }
    
    /**
     * 数据校验
     * @return
     * @throws Exception
     */
    public int validate() throws Exception{
        int length = ((message[12] & 0xFF) <<8) + (message[13] & 0xFF);
        FormatUtils.vaildata(this.message, length);
        
        return length;
    }
}
